<?php
if ( !defined( "IN_UCHOME" ) ) exit( "Access Denied" );
$param['id'] = intval($_GET['id']);
realname_get();
require_once('class.show.php');						
$show = new show;
$event = $show->get_data($param['id']);
$purview = $show->check_user($param['id']);
if(!$purview || empty($event)){
	header('Content-type: text/html; charset=' . $_SC['charset']);
	echo "<script type='text/javascript'>alert('你没有参加该活动，还不能上传照片');top.location.href = 'action.php?ac=show&id={$param['id']}';</script>";
	exit();
}

$temp= $_FILES['picture'];
$photo = array();
$_FILES['picture'] = array();
foreach($temp['name'] as $key=>$val){
	if($temp['error'][$key] == 0 && $temp['size'][$key]  > 0){
		$photo[] = array(
			'name'=>$temp['name'][$key],
			'type'=>$temp['type'][$key],
			'size'=>$temp['size'][$key],
			'tmp_name'=>$temp['tmp_name'][$key]
		);
	}
}
$data = array();
foreach($photo as $_FILES['picture']){
	$data[] = $show->upload();
}

$param['uid'] = intval($uid);
$param['username'] = $_SGLOBAL['supe_username'];
$param['dateline'] = $_SERVER['REQUEST_TIME'];

foreach($data as $val){
	if($val['status'] == 200){
		$param['img'] = get_big_img($val['message'][0], $val['message'][1]);
		$param['ext'] = $val['message'][1];
		inserttable('app_action_album', $param);
	}
}

if($data['privite'] != 2){
	include_once(S_ROOT.'./action/class.news.php');
	$feed = array(
		'subject'=>"<a href='action.php?ac=show&id={$event['id']}'>{$event['subject']}</a>",
		'photo'=>"<a href='action.php?ac=album&id={$event['id']}'>照片</a>",
	);
	feeds::add($feed, 3);
}

if($uid != $event['uid']){
	include_once(S_ROOT.'./source/function_cp.php');
	$note = "<font color=green>活动信息</font>：<a href='space.php?uid={$uid}'>{$_SN[$uid]}</a> 在活动《<a href=\"action.php?ac=show&id={$event['id']}\">{$event['subject']}</a>》中上传了照片，快去<a href='action.php?ac=album&id={$event['id']}'>审核</a>";			
	notification_add($event['uid'], 'event', $note);
}

echo "<script type='text/javascript'>parent.callBack({$param['id']});</script>";

function get_big_img($img, $ext)
{
	return substr($img, 0, -(strlen($ext) + 3));
}
?>